<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <div id="app">
    <p>生命周期钩子函数：类似于人的生老病死，会自动执行</p>
    <p>{{msg}}</p>
    <button @click="destroy">销毁</button>
  </div>
  <script src="../vue.js"></script>
  <script>
    let vm = new Vue({
      el: '#app',
      data: {
        msg: 'hello'
      },
      methods: {
        fn1() {
          console.log('hello world');
        },
        destroy() {
          this.$destroy()
        }
      },
      beforeCreate() {
        console.log('1.beforeCreate:实例创建前');
        // console.log(this.msg);
        // this.fn1()
      },
      created() {
        console.log('2.created:实例创建后');
        console.log(this.msg);
        this.fn1()
      },
      beforeMount() {
        console.log('3.beforeMount:页面渲染前');
        console.log(this.msg);
        this.fn1()
      },
      mounted() {
        console.log('4.mounted:页面渲染之后');
      },
      beforeUpdate() {
        console.log('5.beforeUpdate:更新前');
      },
      updated() {
        console.log('6.updated:更新后');
      },
      beforeDestroy() {
        console.log('7.beforeDestroy:实例销毁前');
      },
      destroyed() {
        console.log('8.destroyed:实例销毁后');
      },
    })
  </script>
</body>
</html>